package com.api.shopapi.service.impl;


import com.api.shopapi.entity.UserAddress;
import com.api.shopapi.mapper.UserAddressMapper;
import com.api.shopapi.service.UserAddressService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("UserAddressServiceImplOne")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, rollbackFor = Throwable.class, timeout = 5000)
public class UserAddressServiceImpl implements UserAddressService {

    @Autowired
    private UserAddressMapper userAddressMapper;

    @Override
    public List<UserAddress> getList() {
        return userAddressMapper.getList();
    }

    @Override
    public void insert(UserAddress userAddress) {
        userAddressMapper.insert(userAddress);
    }

    @Override
    public PageInfo<UserAddress> getPageInfo(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<UserAddress> listUserAddress =userAddressMapper.getList();
        return new PageInfo<>(listUserAddress);
    }

    @Override
    public UserAddress getByUserAddressCode(String userAddressCode) {
        return  userAddressMapper.getByUserAddressCode(userAddressCode);
    }

    @Override
    public void update(UserAddress userAddress) {
        userAddressMapper.update(userAddress);
    }

    @Override
    public List<UserAddress> getMyAddressList(String userCode) {
        return userAddressMapper.getMyAddressList(userCode);
    }

    @Override
    public int delete(String userAddressCode) {
        return userAddressMapper.delete(userAddressCode);
    }

    @Override
    public int addressSetDefault0(String userCode) {
        return userAddressMapper.addressSetDefault0(userCode);
    }

    @Override
    public int addressSetDefault1(String userAddressCode) {
        return userAddressMapper.addressSetDefault1(userAddressCode);
    }

}
